/*
 * cpu.v
 *
 * Copyright 2024 dh33ex <dh33ex@riseup.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA or visit <http://www.gnu.org/licenses/>.
 *
 *
 */

module cpu (
    input               i_clk,
    input               i_rst,

    input      [31:0]   i_instr,
    output     [31:0]   o_PC,

    input      [31:0]   i_ram_rd,
    output              o_ram_we,
    output     [31:0]   o_ram_addr,
    output     [31:0]   o_ram_wd
);

    wire       b_src;
    wire       lnk_trig;
    wire       reg1_we;
    wire [1:0] reg1_src;
    wire [1:0] pc_src;
    wire [3:0] alu_sel;
    wire [3:0] nzvc;

    control_unit control_unit(
        .i_clk(i_clk),
        .i_rst(i_rst),
        .i_instr(i_instr),
        .i_NZVC(nzvc),

        .o_reg1_we(reg1_we),
        .o_B_src(b_src),
        .o_reg1_src(reg1_src),
        .o_PC_src(pc_src),
        .o_ALU_sel(alu_sel),

        .o_lnk_trig(lnk_trig),
        .o_ram_we(o_ram_we)
    );

    data_path data_path(
        .i_clk(i_clk),
        .i_rst(i_rst),

        .i_lnk_trig(lnk_trig),
        .i_reg1_we(reg1_we),
        .i_B_src(b_src),

        .i_reg1_src(reg1_src),
        .i_PC_src(pc_src),
        .i_ALU_sel(alu_sel),

        .o_ram_we(o_ram_we),
        .o_NZVC(nzvc),

        .i_instr(i_instr),
        .o_PC(o_PC),
        .i_ram_rd(i_ram_rd),
        .o_ram_addr(o_ram_addr),
        .o_ram_wd(o_ram_wd)
);

endmodule
